package com.learn.springboot3.controller;

import cn.hutool.core.util.RandomUtil;
import com.learn.springboot3.pojo.Demo;
import com.learn.springboot3.service.DemonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: DemoController
 * Package: com.learn.springboot3.controller
 * Description:
 *
 * @Author jiangCheng
 * @Create 2024/10/22 19:50
 * @Version 1.0
 */
@RestController
@RequestMapping("demo")
public class DemoController {
    @Autowired
    private DemonService demonService;
    @RequestMapping("add")
   public String add(){
        List<Demo> demos = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            Demo demo = new Demo();

            demo.setName(RandomUtil.randomString(6));
            demo.setAge(i);
            demos.add(demo);
            if (i%1000==0){
                demonService.saveBatch(demos);
                demos = new ArrayList<>();
            }
        }



       return "ok";
   }
}
